import Vue from "vue"
import Vuex from 'vuex'
import cart from './modules/cart.js'
import user from './modules/user.js'
Vue.use(Vuex)
const store = new Vuex.Store({
	modules: {
		cart,
		user
	},
	getters: {
		// 购物车总数量
		allCount(state) {
			let a = 0
			state.cart.cart.forEach(item => {
				if (item.goods_state) {
					a += item.goods_count
				}
			})
			return a
		},
		allSelect(state) {
			return state.cart.cart.every(item => item.goods_state === true)
		},
		allPrice(state) {
			let price = 0
			state.cart.cart.forEach(item => {
				if (item.goods_state) {
					price += item.goods_price * item.goods_count
				}
			})
			return price
		}
	}
})
export default store
